package smartclass.fragment;

import java.util.ArrayList;

import smartclass.adapter.StudentAdapter;
import smartclass.data.FinalValues;
import smartclass.entity.StudentInfo;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.jeremyfeinstein.slidingmenu.example.R;

@SuppressLint("ValidFragment")
public class TeacherListStudentFragment extends Fragment {

	private ListView listStudent;
	private Context context;
	private ArrayList<StudentInfo> arrayStudentInfos;
	private StudentAdapter adapter;

	public TeacherListStudentFragment(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		arrayStudentInfos = new ArrayList<StudentInfo>();
	}

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.list_student, null);
		listStudent = (ListView) v.findViewById(R.id.listStudent);
		listStudent.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				// TODO Auto-generated method stub
				StudentInfo student = arrayStudentInfos.get(position);
				LayoutInflater inflater = LayoutInflater.from(context);
				View v = inflater.inflate(R.layout.information_student_dialog,
						null);

				AlertDialog.Builder builder = new AlertDialog.Builder(context);
				builder.setTitle("Infomation Student");
				builder.setIcon(R.drawable.pollen_flower);
				builder.setView(v);
				TextView tvId = (TextView) v.findViewById(R.id.idStudentInfo);
				TextView tvName = (TextView) v
						.findViewById(R.id.nameStudentInfo);
				TextView tvClass = (TextView) v
						.findViewById(R.id.classStudentInfo);
				TextView tvNumberPhone = (TextView) v
						.findViewById(R.id.numberPhoneStudentInfo);
				tvId.setText(student.getId() + "");
				tvName.setText(student.getName());
				tvClass.setText(student.getClassName());
				tvNumberPhone.setText(student.getPhoneNumber());
				builder.setPositiveButton("View Screen", new OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						FinalValues.displayNotification(context, "View Screen");
					}
				}).setNegativeButton("Cancel", null)
						.setNeutralButton("Chat", new OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								// TODO Auto-generated method stub
								FinalValues.displayNotification(context, "Chat");
							}
						});
				builder.create().show();
			}
		});
		return v;
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		adapter = new StudentAdapter(context, R.layout.row, arrayStudentInfos);
		listStudent.setAdapter(adapter);
		StudentInfo student = new StudentInfo();
		student.setName("Tran Van Thang");
		student.setGender("male");
		arrayStudentInfos.add(student);
		StudentInfo student1 = new StudentInfo();
		student1.setName("Bui Thi Hong Dieu");
		student1.setGender("female");
		arrayStudentInfos.add(student1);
	}
}
